/*
 * @User 		@Company 	@Date
 * marcusbui	VNNET24  	May 20, 2011
 */

package tsb.com.html5.common.service;

import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import tsb.com.html5.base.BaseService;
import tsb.com.html5.common.dao.ICommonDao;
import tsb.com.html5.common.item.SearchItem;
import tsb.com.html5.common.param.GetApplicationCachedDataParam;
import tsb.com.html5.common.param.GetSearchResultParam;
import tsb.com.html5.common.util.Constant;
import tsb.com.html5.file.dao.IFileDao;
import tsb.com.html5.file.item.FileItem;
import tsb.com.html5.file.param.GetFileParam;
import tsb.com.html5.product.item.CategoryItem;
import tsb.com.html5.product.item.ProductItem;
import tsb.com.html5.product.param.GetCategoryParam;
import tsb.com.html5.product.param.GetProductParam;
import tsb.com.html5.product.service.IProductService;

// TODO: Auto-generated Javadoc
/**
 * The Class ProductService.
 */
public class CommonService extends BaseService implements ICommonService {
	
	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = 1L;
	
	/** The product service. */
	@Autowired
	private IProductService productService;
	
	/** The file dao. */
	@Autowired
	private IFileDao fileDao;
	
	/** The common dao. */
	@Autowired
	private ICommonDao commonDao;
	
	/* (non-Javadoc)
	 * @see tsb.com.html5.common.service.ICommonService#getApplicationCachedData(tsb.com.html5.common.param.GetApplicationCachedDataParam)
	 */
	public HashMap<String, Object> getApplicationCachedData(
			GetApplicationCachedDataParam parm) throws Exception {
		HashMap<String, Object> returnMap = new HashMap<String, Object>();
		try{
			
			//Product Category
			GetCategoryParam getCategoryParam = new GetCategoryParam();
			List<CategoryItem> categoryList = productService.getAllCategory(getCategoryParam);
			returnMap.put(Constant.CATEGORY, categoryList);
			
			List<FileItem> fileList = fileDao.getAllFiles();
			returnMap.put(Constant.FILE_LIST, fileList);
			
			List<ProductItem> poductList = productService.getProduct(new GetProductParam());
			returnMap.put(Constant.PRODUCT_LIST, poductList);
			
		}catch(Exception e){
			throw e;
		}
		return returnMap;
	}

	/* (non-Javadoc)
	 * @see tsb.com.html5.common.service.ICommonService#getFileById(tsb.com.html5.file.param.GetFileParam)
	 */
	public FileItem getFileById(GetFileParam parm) throws Exception {
		FileItem returnFile = null;
		try{
			if(parm.getFileId()!=null && parm.getFileId().length()>0){
				returnFile = fileDao.getFileById(parm);
			}
			
		}catch(Exception e){
			throw e;
		}
		return returnFile;
	}

	/* (non-Javadoc)
	 * @see tsb.com.html5.common.service.ICommonService#getSearchResult(tsb.com.html5.common.param.GetSearchResultParam)
	 */
	public List<SearchItem> getSearchResult(GetSearchResultParam parm)
			throws Exception {
		try{
			List<SearchItem> objectList = (List<SearchItem>) commonDao.getSearchResult(parm);
			return objectList;	
		}catch(Exception e){
			throw e;
		}
	}

}
